Create P2M map during Mini-OS boot (fixes 'xm dump-core').
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 1 Mar 2007 12:23:44 +0000 (12:23 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 1 Mar 2007 12:23:44 +0000 (12:23 +0000)
Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
extras/mini-os/arch/ia64/mm.c
extras/mini-os/arch/x86/mm.c
extras/mini-os/include/mm.h
extras/mini-os/mm.c

index ad5acccc7eb30425aaf7eb2e8ff360111f7beb72..dd1fb9dc7810e29ec827d99066d55feab08dd5c1 100644 (file)
@@ -130,3 +130,7 @@ map_frames(unsigned long* frames, unsigned long n)
        return (void*) __va(frames[0] << PAGE_SHIFT);
 }
 
+void arch_init_p2m(unsigned long max_pfn)
+{
+    printk("Warn: p2m map not implemented.\n");
+}
index d0fe762792622dd4f52f42b8251ed372502f7c59..d1508f8263cd3660f759e602c795f1703ff25e72 100644 (file)
@@ -402,6 +402,49 @@ void *map_frames(unsigned long *f, unsigned long n)
     }
 }
 
+
+void arch_init_p2m(unsigned long max_pfn)
+{
+#define L1_P2M_SHIFT    10
+#define L2_P2M_SHIFT    20    
+#define L3_P2M_SHIFT    30    
+#define L1_P2M_ENTRIES  (1 << L1_P2M_SHIFT)    
+#define L2_P2M_ENTRIES  (1 << (L2_P2M_SHIFT - L1_P2M_SHIFT))    
+#define L3_P2M_ENTRIES  (1 << (L3_P2M_SHIFT - L2_P2M_SHIFT))    
+#define L1_P2M_MASK     (L1_P2M_ENTRIES - 1)    
+#define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
+#define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
+    
+    unsigned long *l1_list, *l2_list, *l3_list;
+    unsigned long pfn;
+    
+    l3_list = (unsigned long *)alloc_page(); 
+    for(pfn=0; pfn<max_pfn; pfn++)
+    {
+        if(!(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)))
+        {
+            l2_list = (unsigned long*)alloc_page();
+            if((pfn >> L3_P2M_SHIFT) > 0)
+            {
+                printk("Error: Too many pfns.\n");
+                do_exit();
+            }
+            l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
+        }
+        if(!(pfn % (L1_P2M_ENTRIES)))
+        {
+            l1_list = (unsigned long*)alloc_page();
+            l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] = 
+                virt_to_mfn(l1_list); 
+        }
+
+        l1_list[pfn & L1_P2M_MASK] = pfn_to_mfn(pfn); 
+    }
+    HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
+        virt_to_mfn(l3_list);
+    HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
+}
+
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
 {
 
index cd53a4bf252af587dfb183a4503f58ea8a4deed0..a9c0f2c181c51b2c0dd69a2e5137b93ea701b7b0 100644 (file)
@@ -55,6 +55,7 @@ static __inline__ int get_order(unsigned long size)
 
 void arch_init_demand_mapping_area(unsigned long max_pfn);
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
+void arch_init_p2m(unsigned long max_pfn_p);
 
 void *map_frames(unsigned long *f, unsigned long n);
 
index a24a521cf647c373df1daaa2511d444e27cc39cd..11e249d4218787fea1ba1a6882ac15ba3c837ebf 100644 (file)
@@ -379,6 +379,8 @@ void init_mm(void)
     init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
     printk("MM: done\n");
 
+    arch_init_p2m(max_pfn);
+    
     arch_init_demand_mapping_area(max_pfn);
 }